package com.ruoyi.leave.instener;

import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.impl.event.EventSubscriptionPayloadMappingProvider;
import org.activiti.runtime.api.impl.VariablesMappingProvider;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.activiti.spring.boot.DefaultActivityBehaviorFactoryMappingConfigurer;
import org.activiti.spring.process.ProcessVariablesInitiator;
import org.springframework.context.annotation.Configuration;

import java.util.Collections;

@Configuration
@Slf4j
public class ActivitiConfiguration extends DefaultActivityBehaviorFactoryMappingConfigurer {


    public ActivitiConfiguration(VariablesMappingProvider variablesMappingProvider, ProcessVariablesInitiator processVariablesInitiator, EventSubscriptionPayloadMappingProvider eventSubscriptionPayloadMappingProvider) {
        super(variablesMappingProvider, processVariablesInitiator, eventSubscriptionPayloadMappingProvider);
    }

    @Override
    public void configure(SpringProcessEngineConfiguration springProcessEngineConfiguration) {
        super.configure(springProcessEngineConfiguration);
        springProcessEngineConfiguration.setEventListeners(
                Collections.singletonList(new ActivitiTaskEventListener(springProcessEngineConfiguration.getHistoryService(),
                        springProcessEngineConfiguration.getTaskService(), springProcessEngineConfiguration.getRuntimeService())));
    }
}
